/*
 ********************************************************************************
 * Copyright (c) 2013 Samsung Electronics, Inc.
 * All rights reserved.
 *
 * This software is a confidential and proprietary information of Samsung
 * Electronics, Inc. ("Confidential Information"). You shall not disclose such
 * Confidential Information and shall use it only in accordance with the terms
 * of the license agreement you entered into with Samsung Electronics.
 ********************************************************************************
 */

package adjust_volume;

import java.util.LinkedList;
import java.util.List;

import android.content.Context;


import adjust_volume.GestureDrawerApplier;

/**
 * A class holding {@link DrawerApplier DrawerAppliers}.
 */
public final class ApplierChain {

	private final List<DrawerApplier> mAppliers;

	private ApplierChain() {
		mAppliers = new LinkedList<DrawerApplier>();
	}
	
	/**
	 * Creates an {@link ApplierChain} with a predefined set of supported {@link DrawerApplier DrawerAppliers}.
	 * 
	 * @param context
	 *            Android {@link Context}
	 * @param drawerOpener
	 *            {@link DrawerOpener} that the chain will apply its appliers to
	 * @return fully created {@link ApplierChain}
	 */
	public static ApplierChain createFor(Context context,
			DrawerOpener drawerOpener) {
		ApplierChain chain = new ApplierChain();

		final GestureDrawerApplier gestureApplier = new GestureDrawerApplier(
				context, drawerOpener);
		if (gestureApplier.isSupported()) {
			chain.add(gestureApplier);
		}
		/*final AccelerationDrawerApplier accelerationApplier = new AccelerationDrawerApplier(
				context, drawerOpener);
		chain.add(accelerationApplier);*/

		return chain;
	}

	private void add(DrawerApplier applier) {
		mAppliers.add(applier);
	}

	/**
	 * Enables all the {@link DrawerApplier DrawerAppliers} added to this chain.
	 */
	public void enable() {
		for (DrawerApplier applier : mAppliers) {
			applier.enable();
		}
	}

	/**
	 * Disables all the {@link DrawerApplier DrawerAppliers} added to this chain.
	 */
	public void disable() {
		for (DrawerApplier applier : mAppliers) {
			applier.disable();
		}
	}
}
